#ifndef __ILIB_TP_CONNECTION_H_20120325__
#define __ILIB_TP_CONNECTION_H_20120325__

#include "../util/h/iAtomic.h"
#include "../util/h/iSmartPtr.h"
#include "../util/h/iLock.h"

enum TP_OPTION
{
    TP_OPT_LOCAL_ADDR,     // out char*
    TP_OPT_REMOTE_ADDR,    // out char*
    TP_OPT_PROTO_TYPE,     // out uint32, readonly
};

class iMsgDB;
class iTPConnection
{
public:
    static iTPConnection* new_instance(const char* remote, const char* local=NULL, iAllocator* alloc=iSingleton<iAllocator>::instance());

    enum CTYPE { ORIGINAL, PBN };

	class iSink
	{
	public:
		virtual void on_connect_confirm(int32_t result, iMsgDB* rsp) = 0;
		virtual void on_data_indication(iMsgDB* msg) = 0;
		virtual void on_close(int32_t reason) = 0;
	};

	virtual int32_t connect_request (iMsgDB* request,  iSink* sink) = 0;
	virtual int32_t connect_response(iMsgDB* response, iSink* sink) = 0;
	virtual int32_t close() = 0;
    virtual int32_t send_data(iMsgDB* data) = 0;
    virtual int32_t get_option(TP_OPTION, void* optval, int32_t optlen) = 0;
    virtual int32_t set_option(TP_OPTION, void* optval, int32_t optlen) = 0;
    virtual void    release() = 0;
};

#endif  //__ILIB_TP_CONNECTION_H_20120325__
